package cn.sccl.web.action;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.sccl.domain.User;
import cn.sccl.service.UserService;

/**
 * @author 饶爽
 * @time 2019年9月8日 下午4:55:52
 * @version 1.0.0
 * 用户登录的Action 
*/
public class UserAction extends ActionSupport implements ModelDriven<User>{
    private User user = new User();
    private UserService userService;
    
    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    public String login() throws Exception{
//        System.out.println(userService);
        //1 调用Service执行登陆逻辑
        User u = userService.getUserByCodePassword(user);
        //2 将返回的User对象放入session域
        ActionContext.getContext().getSession().put("user", u);
        //3 重定向到项目首页
        
        return "toHome";
    }
    @Override
    public User getModel() {
        return user;
    }
    
}
